/*******************************************************************************************************

Table A7: Difference-in-differences estimates: time series specifications with different estimation techniques

*******************************************************************************************************/


*Set directory path
*cd "C:\Users\tsa23\Documents\petitions\replication files"
cd "C:\Users\tsa23\Dropbox\Swing_riots\petitions\stata\replication files"


clear all

*read in our main dataset
use dta/did_rep.dta

*Elminate contrituencies which are not part of case G
drop if ID == 45 //University of Cambridge
drop if ID == 191 //University of Oxford
keep if new == 1 | drummond == .

drop if year==1830 | year==1831 | year==1832

gen treatgroup = 0
replace treatgroup =  1 if new==1 

gen treatinter = treatperiod*treatgroup

label var treatinter "T * A" 
label var treatgroup "T"
label var treatperiod "A"

tsset ID year


xtreg petitions treatinter  i.year, fe cluster(ID)
outreg2 treatinter  using results\TableA7, replace addt(Method, OLS, Borough FE, yes, Time FE, yes, Treatment, G) asterisk(coef) auto(2) ctitle (Petitions) label nocons keep(treatinter ) se  symbol(**,*,+) tex(frag)

xtreg ln_petitions treatinter  i.year, fe cluster(ID)
outreg2 treatinter  using results\TableA7, append addt(Method, OLS, Borough FE, yes, Time FE, yes, Treatment, G) asterisk(coef) auto(2) ctitle (Log(petitions +1)) label nocons keep(treatinter ) se  symbol(**,*,+) tex(frag)


*robust means QMLE that does not assume that the average and variance is the same.
xtpoisson petitions treatinter  i.year, fe robust  irr
outreg2 treatinter  using results\TableA7, append addt(Method, Poisson, Borough FE, yes, Time FE, yes, Treatment, G) asterisk(coef) auto(2) ctitle (Petitions) label nocons keep(treatinter ) se  symbol(**,*,+) tex(frag)

gen asinh_petitions = asinh(petitions)
xtreg asinh_petitions treatinter  i.year, fe cluster(ID)
outreg2 treatinter  using results\TableA7, append addt(Method, OLS, Borough FE, yes, Time FE, yes, Treatment, G) asterisk(coef) auto(2) ctitle ("asinh(Petitions)") label nocons keep(treatinter ) se  symbol(**,*,+) tex(frag)

*Interpretation asinh

summ petitions if treatinter==0, meanonly
scalar petitions0 = r(mean)
scalar b  = _b[treatinter]
display petitions0

* exact level and percent effects at baseline petitions0:
scalar dy   = petitions0*(cosh(b)-1) + sqrt(1+petitions^2)*sinh(b)
scalar pct  = dy / petitions0
display "Δpetitions = " dy ",   %Δ ≈ " 100*pct "%"

* large-y approximation (log-like):
display "Approx %Δ (large y): " 100*(exp(b)-1) "%"


clear all

*read in our main dataset
use dta/did_rep.dta

*Elminate contrituencies which are not part of case L
drop if ID == 45 //University of Cambridge
drop if ID == 191 //University of Oxford
keep if sch_A==1 | sch_B == 1 | drummond!=.

drop if year==1830 | year==1831 | year==1832

gen treatgroup = 0
replace treatgroup =  1 if sch_A==1 

gen treatinter = treatperiod*treatgroup

label var treatinter "T * A" 
label var treatgroup "T"
label var treatperiod "A"

tsset ID year

xtreg petitions treatinter  i.year, fe cluster(ID)
outreg2 treatinter  using results\TableA7, append addt(Method, OLS, Borough FE, yes, Time FE, yes, Treatment, L) asterisk(coef) auto(2) ctitle (Petitions) label nocons keep(treatinter ) se  symbol(**,*,+) tex(frag)

xtreg ln_petitions treatinter  i.year, fe cluster(ID)
outreg2 treatinter  using results\TableA7, append addt(Method, OLS, Borough FE, yes, Time FE, yes, Treatment, L) asterisk(coef) auto(2) ctitle (Log(petitions +1)) label nocons keep(treatinter ) se  symbol(**,*,+) tex(frag)


*robust means QMLE that does not assume that the average and variance is the same.
xtpoisson petitions treatinter  i.year, fe robust  irr
outreg2 treatinter  using results\TableA7, append addt(Method, Poisson, Borough FE, yes, Time FE, yes, Treatment, L) asterisk(coef) auto(2) ctitle (Petitions) label nocons keep(treatinter ) se  symbol(**,*,+) tex(frag)

gen asinh_petitions = asinh(petitions)
xtreg asinh_petitions treatinter  i.year, fe cluster(ID)
outreg2 treatinter  using results\TableA7, append addt(Method, OLS, Borough FE, yes, Time FE, yes, Treatment, L) asterisk(coef) auto(2) ctitle ("asinh(Petitions)") label nocons keep(treatinter ) se  symbol(**,*,+) tex(frag)


*Interpretation asinh

summ petitions if treatinter==0, meanonly
scalar petitions0 = r(mean)
scalar b  = _b[treatinter]
display petitions0

* exact level and percent effects at baseline petitions0:
scalar dy   = petitions0*(cosh(b)-1) + sqrt(1+petitions^2)*sinh(b)
scalar pct  = dy / petitions0
display "Δpetitions = " dy ",   %Δ ≈ " 100*pct "%"

* large-y approximation (log-like):
display "Approx %Δ (large y): " 100*(exp(b)-1) "%"

